<!--
 * @Descripttion: 
 * @version: 1.0
 * @Author: Sam
 * date: 2021-03-01 16:01:08
 * @LastEditors: Sam
 * @LastEditTime: 2021-12-09 10:38:43
-->
{include file="common/public/header"}
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form padsome" action="" method="post" onsubmit="return false">    
                  <div class="layui-form-item">
                    <label class="layui-form-label"><span class="c-red">*</span> 问卷主题</label>
                    <div class="layui-input-block">
                      <select name="survey_id">
                        <option value="">选择主题</option>
                        {volist name="survey" id="v"} 
                            <option value="{$v.id}">{$v.title}</option>
                        {/volist}
                      </select>
                    </div>
                  </div>                
                  <div class="layui-form-item">
                  <label class="layui-form-label"><span class="c-red">*</span> 题目</label>
                  <div class="layui-input-block">
                    <input type="text" name="title" required  value="" lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
                  </div>
                </div>
              <div class="layui-form-item">
                <label class="layui-form-label"><span class="c-red">*</span> 类型</label>
                <div class="layui-input-block" >
                  <input type="radio" name="type" lay-verify="required" lay-filter="type" value="1" title="单选">
                  <input type="radio" name="type" lay-verify="required"  lay-filter="type" value="2" title="多选">
                  <input type="radio" name="type" lay-verify="required" lay-filter="type" value="3" title="填空">
                  <input type="radio" name="type" lay-verify="required"  lay-filter="type" value="4" title="选择填空">
                </div>
              </div>
              <div class="layui-form-item temp" style="display: none;">
                <label class="layui-form-label">选项</label>
                <div class="layui-input-block">
                  <table class="layui-table">
                    <colgroup>
                      <col  width="150">
                      <col>
                      <col>
                    </colgroup>
                    <thead>
                      <div class="layui-btn add_option">添加</div>
                      <tr>
                        <th>选项编号</th>
                        <th>选项标题</th>
                        <th style="text-align:center">操作</th>
                      </tr> 
                    </thead>
                    <tbody class="option_temp">
 
                      
                    </tbody>
                  </table>
                </div>
              </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block layui-layout-admin">
                                <div class="layui-footer" style="left: 0;">
                                    <button class="layui-btn" lay-submit lay-filter="submit">立即提交</button>
                                    <button class="layui-btn layui-btn-primary" type="button" onclick="close_frame()">返回</button>
                                </div>
                            </div>
                        </div>
                </form>
            </div>
        </div>
    </div>
</div>
 
{include file="common/public/footer" /}
{block name="script"}
<script>
    layui.extend({
        xmSelect: 'xm-select'
    }).use(['index', 'form', 'layarea', 'laydate', 'xmSelect'], function(){
        var $       = layui.$;
        var form    = layui.form;


        form.render();
        // 监听表单提交
        form.on('submit(submit)', function(data){
            Post('', data.field, function(res) {
                if (res.code == 1) {
                    alert_success(res.msg, function() {
                        parent.layui.table.reload('table', {where: parent.where});
                        close_frame();
                    })
                } else {
                    alert_error(res.msg);
                }
            });
            return false;
        });

            form.on('radio(type)', function(data){
                  var type = data.value;
                  if(type != 3){
                        $('.temp').show();
                  }else{
                      $('.temp').hide();
                  }
                }); 
                $('.add_option').click(function(){
                 $('.option_temp').append('<tr>'
                                    +'<td><input type="text" name="option_number[]"  class="layui-input"></td>'
                                    +'<td><input type="text" name="option_name[]" class="layui-input"></td>'
                                    + '<td style="text-align:center;cursor: pointer;color: blue;" class="del">删除</td>'
                                    + '</tr>'
                                    
                 );
              });
              $(document).on('click','.del',function(){
                $(this).parent().remove();
              })
});
</script>

{/block}

